$(function(){
	$('.field-container-header-list-item').on('click',function(){
		let index=$(this).index();
		$(this).addClass('active').siblings().removeClass('active');
		$('.field-container-content-item').eq(index).addClass('active').siblings().removeClass('active');
	})

	$('#submit').on('click',function(){
		let username=$('#username').val();
		if (!username) {
			$('#err-msg').text('请输入姓名').slideDown(500);
			return;
		}
		let phone=$('#phone').val();
		if (!phone) {
			$('#err-msg').text('请输入手机号').slideDown(500);
			return;
		}
		let phoneRex=/^1[3456789]\d{9}$/;
		if (!phoneRex.test(phone)) {
			$('#err-msg').text('请输入正确的手机号').slideDown(500);
			return;
		}
		let email=$('#email').val();
		if (!email) {
			$('#err-msg').text('请输入邮箱').slideDown(500);
			return;
		}
		let emailRex= /^([A-Za-z0-9_\-\.\u4e00-\u9fa5])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,8})$/;
		if (!emailRex.test(email)) {
			$('#err-msg').text('请输入正确的邮箱').slideDown(500);
			return;
		}
		let info=$('#info').val();
		if (!info) {
			$('#err-msg').text('请输入咨询信息').slideDown(500);
			return;
		}
		$('#err-msg').slideUp(300);
		let submitData={
			name:username,
			phone,
			email,
			information:info,
			fid: 6
		}
		$('#err-msg').removeClass('success');
		let currentSubmit=$(this);
		//let url='https://cloudflare.jadegital.com/plugin/message/do/addmsg.html';
		currentSubmit.text('正在提交...').attr('disabled',true);
		$.ajax({
				url:'http://192.168.136.1:3001/contact',
				type:'POST',
				data:submitData,
				success:function(res){
					console.log(res);
					let data=res;
					if (data.code) {
						let successMsg=data.msg||'提交成功';
						$('#err-msg').addClass('success').text(successMsg).slideDown(500);
					} else {
                        let errMsg=data.msg||'提交失败';
						$('#err-msg').text(errMsg).slideDown(500);
                    }
                    currentSubmit.text('提交').attr('disabled',false);
				},
				error:function(error){
					console.log(error)
					let errMsg=error.statusText||'请求错误';
					$('#err-msg').text(errMsg).slideDown(500);
					currentSubmit.text('提交').attr('disabled',false);
				}
		})
	})
})